#ifndef EDFSIGNALINFORMATION_H
#define EDFSIGNALINFORMATION_H

#include <string>
#include <vector>
#include <istream>
#include <ostream>
#include <iostream> //TODO remove
#include <tr1/memory>

#include "edfsignalsource.h"
#include "edfdatarecord.h"

#include <biosignal/biosignal.h>

namespace biosignal
{
namespace edf
{

class EDFModel: public BioSignal
{
public:
    typedef std::vector<EDFSourceSignal>::const_iterator signals_iterator;

    EDFModel(const char* file_name);
    virtual ~EDFModel();
    bool is_edf_plus() const;
    bool has_interruptions() const;
    double datarecord_duration() const;

    virtual void show_header_info(std::ostream& os) const;
    virtual long get_nr_dataframes() const;

protected:
    virtual DataFrame* create_dataframe( TimePeriod bounds, shared_ptr<const montage::Montage> montage ) const;

private:
    std::string m_version;
    std::string m_patient_identification;
    std::string m_recording_identification;
    int m_bytes_in_header;
    std::string m_reserved;
    long m_nr_data_records;
    double m_data_record_duration;
    long m_bytes_per_data_record;
    //EDFTimeKeepingData* timekeeping;

    std::vector<EDFSourceSignal*> _edf_signals;

    bool m_is_edf_plus;
    bool m_has_interruptions;

    istream_ptr biosignal_istream;
    void open_file_as_binary();
    void fill_time_keeping_and_annotations();

    virtual TimePeriod dataframe_time_period(TimePoint time) const throw (BadTimePoint);

    friend class EDFParser;
    friend class EDFDataRecord;
};
typedef std::tr1::shared_ptr<EDFModel> EDFModel_Ptr;

class EDFTal
{
    friend class EDFModel;
    double onset; //in seconds
    double duration; //in seconds
    std::vector<std::string> annotations;
};

}
}
#endif // EDFSIGNALINFORMATION_H
